package src.ten;

import javax.swing.*;
import javax.swing.border.EmptyBorder;
import javax.swing.table.DefaultTableModel;
import java.awt.*;
import java.util.ArrayList;
import java.util.List;

public class ClassInfo extends JFrame {

    JPanel contentPane;
    JTable table;

    public ClassInfo(){
        setTitle("\u7528List\u96C6\u5408\u4F20\u9012\u5B66\u751F\u4FE1\u606F");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setBounds(100,100,392,223);
        contentPane = new JPanel();
        contentPane.setBorder(new EmptyBorder(5,5,5,5));
        contentPane.setLayout(new BorderLayout(0,0));
        setContentPane(contentPane);
        JScrollPane scrollPane = new JScrollPane();
        contentPane.add(scrollPane,BorderLayout.CENTER);
        scrollPane.setViewportView(getTable());
    }

    private JTable getTable(){
        if(table == null){
            table = new JTable();
            table.setRowHeight(23);
            String[] columns = {"姓名","性别","出生日期"};
            DefaultTableModel model = new DefaultTableModel(columns,0);
            table.setModel(model);
            List<String> students = getStudents();
            for (String student : students) {
                String[] args = student.split(",");
                model.addRow(args);
            }
        }
        return table;
    }

    private List<String> getStudents(){
        List<String> list = new ArrayList<String>();
        list.add("李哥,男,1981-1-1");
        list.add("小陈,女,1981-1-1");
        list.add("小刘,男,1981-1-1");
        list.add("小张,男,1981-1-1");
        list.add("小懂,男,1981-1-1");
        list.add("小吕,男,1981-1-1");
        return list;
    }
}
